import java.util.Scanner;

/**
 * @author HW
 */
public class MaxCommonDivisor {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int a=scan.nextInt();
        int b= scan.nextInt();
        int n=a%b;
        while(a%b!=0){

            a=b;
            b=n;
            n=a%b;
        }
        System.out.println(b);
    }
}
